#include <jni.h>
#include <string>


jint  chcksinglegoogs(int weight,jint *gs,jint *os, jint leng){
    int temp=0;
    for(jint i=0;i<leng;i++){
        jint min=gs[i]-os[i];
        jint max=gs[i]+os[i];
        if(weight>min&&weight<max){
            temp=i;
            break;
        }
    }
    return temp;
}



extern "C" JNIEXPORT jintArray
JNICALL
Java_com_dlc_felear_xiaoensale_helper_DataHandle_checkWhichOne( JNIEnv *env, jobject obj, jint weight,jintArray goodsStd,jintArray offsets) {
    jint len = env->GetArrayLength(goodsStd);
    jintArray jarr = env->NewIntArray(len);
    jint *p=env->GetIntArrayElements(jarr, 0);
    jint *gs = env->GetIntArrayElements(goodsStd, 0);
    jint *os = env->GetIntArrayElements(offsets, 0);
    for(jint i=0;i<len;i++){
        p[i]=0;
    }
    jint min=0,max=0;
    max=gs[0]+os[0];
    min=gs[len-1]-os[len-1];
    if(weight>min&&weight<max){
        //单个商品
        p[chcksinglegoogs(weight,gs,os,len)] =1;
    } else if(weight>max){

    }
    env->ReleaseIntArrayElements(jarr,p,0);
    return jarr;
}

extern "C" JNIEXPORT jstring

JNICALL
Java_com_example_admin_testdemo_helper_DataHandle_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

